package com.shujia.day15.homework;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/*
     假如有以下email数据“aa@sohu.com,bb@ 163.com,cc@sina.com,..”
     现需要把email 中的用户部分和邮件地址部分分离，分离后以键值对应的方式放入HashMap？
 */
public class Test3 {
    public static void main(String[] args) {
        String str = "aa@sohu.com,bb@ 163.com,cc@sina.com";
        HashMap<String, String> map1 = new HashMap<>();

        String[] infos = str.split(",");
        for (String info : infos) {
            String[] split = info.split("@");
            String user = split[0];
            String address = split[1].trim();
            map1.put(user, address);
        }

        Set<Map.Entry<String, String>> entries = map1.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String user = entry.getKey();
            String address = entry.getValue();
            System.out.println("用户：" + user + ", 地址：" + address);
        }

    }
}
